package top.buluoluo.ordersservice.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.buluoluo.commoncore.domain.response.Result;
import top.buluoluo.ordersservice.dto.request.OrderAddRequest;
import top.buluoluo.ordersservice.dto.request.OrderPageRequest;
import top.buluoluo.ordersservice.dto.request.OrderPayRequest;
import top.buluoluo.ordersservice.dto.respone.OrderAddDTO;
import top.buluoluo.ordersservice.dto.respone.OrderDTO;
import top.buluoluo.ordersservice.dto.respone.OrderPayDTO;
import top.buluoluo.ordersservice.dto.result.PageResult;
import top.buluoluo.ordersservice.service.OrderService;

@RestController
@RequestMapping("/order")
@Tag(name = "订单管理", description = "订单管理接口文档")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Operation(summary = "根据订单id分页获取订单信息接口", description = "根据传入的用户id查询对应的订单信息")
    @GetMapping ("/getOrderById/{orderId}")
    public Result<OrderDTO> getOrderById(@PathVariable String orderId ) {
        return orderService.getOrderById(orderId);
    }
    @Operation(summary = "根据用户id分页获取订单信息接口", description = "根据传入的用户id查询对应的订单信息")
    @PostMapping("/getOrderPageById")
    public Result<PageResult<OrderDTO>> getOrderByUserId(@RequestBody OrderPageRequest orderPageRequest) {
        return orderService.getOrderByUserId(orderPageRequest);
    }
    @Operation(summary = "新增订单接口", description = "根据传入的信息新增订单")
    @PostMapping("/addOrder")
    public Result<OrderAddDTO> addOrder(@RequestBody OrderAddRequest orderAddRequest) {
        return orderService.addOrder(orderAddRequest);
    }
    @Operation(summary = "支付订单接口", description = "接受支付信息,改变订单状态")
    @PostMapping("/payOrder")
    public Result<OrderPayDTO> payOrder(@RequestBody OrderPayRequest orderPayRequest) {
        return orderService.payOrder(orderPayRequest);
    }
}
